package com.crrc.dataparse.util;

import com.crrc.dataparse.entity.PaserInfo;
import com.crrc.dataparse.entity.Protocol;
import com.crrc.dataparse.entity.Template;
import com.crrc.dataparse.entity.TemplatePara;
import com.crrc.dataparse.monitor.base.resource.RegionalRC;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class DataInitializer {

    public static PaserInfo getPaserInfo(String filepath) {
        RegionalRC.setProtocolXml(filepath);
        RegionalRC.loadResource(new String[]{"protocol", "template_oid", "templatePara", "canId"});
        Protocol proto = (Protocol) RegionalRC.getResource("protocol").getResource();
        Template template = (Template)RegionalRC.getResource("template_oid").getResource();
        Map<String, TemplatePara> paraMap = (Map)RegionalRC.getResource("templatePara").getResourceMap();
        Map<String, TemplatePara> idParaMap = new HashMap();
        Iterator var6 = paraMap.entrySet().iterator();

        while(var6.hasNext()) {
            Map.Entry<String, TemplatePara> entry = (Map.Entry)var6.next();
            idParaMap.put(((TemplatePara)entry.getValue()).getOid(), entry.getValue());
        }

        PaserInfo paserInfo = new PaserInfo();
        paserInfo.setProtocol(proto);
        paserInfo.setTempParaMap(paraMap);
        paserInfo.setIdParaMap(idParaMap);
        paserInfo.setTemplate(template);

        // 增加空指针检查
        String protoTypeKey = filepath.split("\\.")[0];
        
        return paserInfo;
    }
}
